﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>潜在客户管理</title>
    <#include "../common/link.ftl">
    <script>
       $(function () {
           $('.btn-input').click(function () {
               // 不刷新页面模态框只是隐藏,内容就一直保留,每次点击前清空
               $("#editForm input").val('');
               // 通过事件源.data方法获取自定义属性,会自动封装json详情百度,有则是编辑没有则是添加
               var json = $(this).data("json");
               if(json){
                   // 给编辑回显数据(id隐藏)
                   $("#editForm input[name=id]").val(json.id);
                   $("#editForm input[name=name]").val(json.name);
                   $("#editForm input[name=age]").val(json.age);
                   $("#editForm input[name=qq]").val(json.qq);
                   $("#editForm input[name=tel]").val(json.tel);
                   $("#editForm select[name=gender]").val(json.gender);
                   $("#editForm select[name='job.id']").val(json.jobId);
                   $("#editForm select[name='source.id']").val(json.sourceId);
               }
               // 点击新增或则编辑弹出模态框
               $('#myModal').modal('show');
           });

           //新增编辑模态框的按钮
           $('.btn-add-edit').click(function () {
               //点击提交按钮
               //ajaxSubmit方法可以把表单转为异步的表单，马上提交
               $('#editForm').ajaxSubmit(handlerMessage);
           })


           $('.btn-status').click(function () {
               // 每次点击前清空
               $("#statusForm input").val('');
               // 获取自定义属性
               var json = $(this).data("json");
               if(json){
                   // 回显数据
                   $("#statusId").val(json.id);
                   $("#status").val(json.status);
                   $("#statusName").val(json.name);

               }
               // 弹出模态框
               $('#statusModal').modal('show');
           });

           //修改客户状态模态框的按钮
           $('.btn-statusForm').click(function () {
               //提交表单
               $('#statusForm').ajaxSubmit(handlerMessage);
           })

       })
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "../common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="customer_potential"/>
    <#include "../common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>潜在客户管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/customer/potentialList.do" method="post">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <div class="form-group">
                        <label for="keyword">关键字:</label>
                        <input type="text" class="form-control" id="keyword" name="keyword" value="${(qo.keyword)!}" placeholder="请输入姓名/邮箱">
                    </div>
                    <!-- 超级管理员和经理显示 -->
                    <@shiro.hasAnyRoles name="admin,Market_Manager">
                    <div class="form-group">
                        <label for="dept"> 销售人员:</label>
                        <select class="form-control" id="sellerId" name="sellerId">
                            <option value="-1">全部</option>
                                    <#list sellers! as s>
                                        <option value="${(s.id)!}">${(s.name)!}</option>
                                    </#list>
                        </select>
                        <script>
                            $('select').val(${(qo.sellerId)!})
                            //$("#sellerId option[value='${(qo.sellerId)!}']").prop("selected", true);
                        </script>
                    </div>
                    </@shiro.hasAnyRoles>
                    <button id="btn_query" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> 查询</button>
                    <a href="#" class="btn btn-success btn-input" style="margin: 10px">
                        <span class="glyphicon glyphicon-plus"></span> 添加
                    </a>
                </form>
                <!--编写内容-->
                <div class="box-body table-responsive no-padding ">
                    <table class="table table-hover table-bordered">
                        <tr>
                            <th>编号</th>
                            <th>姓名</th>
                            <th>电话</th>
                            <th>qq</th>
                            <th>职业</th>
                            <th>来源</th>
                            <th>销售员</th>
                            <th>状态</th>
                            <th>录入时间</th>
                            <th>操作</th>
                        </tr>
                            <#list (pageResult.list)! as customer>
                            <tr>
                                <td>${(customer_index)!+1}</td>
                                <td>${(customer.name)!}</td>
                                <td>${(customer.tel)!}</td>
                                <td>${(customer.qq)!}</td>
                                <td>${(customer.job.title)!}</td>
                                <td>${(customer.source.title)!}</td>
                                <td>${(customer.seller.name)!}</td>
                                <td>${(customer.statusName)!}</td>
                                <td>${(customer.inputTime?string("yyyy-MM-dd"))!}</td>
                                <td>
                                    <#-- 自定义属性封装自身的数据(该行),单引号注意 -->
                                    <a class="btn btn-info btn-xs btn-input" data-json='${(customer.json)!}'>
                                        <span class="glyphicon glyphicon-pencil"></span> 编辑
                                    </a>
                                    <a class="btn btn-danger btn-xs btn-status" data-json='${(customer.json)!}'>
                                        <span class="glyphicon glyphicon-pencil"></span> 修改状态
                                    </a>
                                    <a class="btn btn-danger btn-xs btn-trace" data-json='${(customer.json)!}'>
                                        <span class="glyphicon glyphicon-phone"></span> 跟进
                                    </a>
                                        <!-- 超级管理员和经理才能看到 -->
                                    <@shiro.hasAnyRoles name="admin,Market_Manager">
                                        <a class="btn btn-danger btn-xs btn-transfer" data-json='${(customer.json)!}'>
                                            <span class="glyphicon glyphicon-phone"></span> 移交
                                        </a>
                                    </@shiro.hasAnyRoles>
                                </td>
                            </tr>
                            </#list>
                    </table>
                    <!--分页-->
                    <#include "../common/page.ftl">
                </div>
            </div>
        </section>
    </div>
    <#include "../common/footer.ftl">
</div>
<#-- 新增/编辑模态框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">客户新增/编辑</h4>
            </div>
            <form class="form-horizontal" action="/customer/saveOrUpdate.do" method="post" id="editForm">
                <input type="hidden" name="id">
                <div class="form-group" >
                    <label  class="col-sm-3 control-label">客户名称：</label>
                    <div class="col-sm-6">
                        <input type="text" class="form-control" name="name"
                               placeholder="请输入客户姓名"/>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 control-label">客户年龄：</label>
                    <div class="col-sm-6">
                        <input type="number" class="form-control" name="age"
                               placeholder="请输入客户年龄"/>
                    </div>
                </div>
                <div class="form-group" >
                    <label  class="col-sm-3 control-label">客户性别：</label>
                    <div class="col-sm-6">
                        <select class="form-control" name="gender">
                            <option value="1">男</option>
                            <option value="0">女</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 control-label">客户电话：</label>
                    <div class="col-sm-6">
                        <input type="text" class="form-control" name="tel"
                               placeholder="请输入客户电话"/>
                    </div>
                </div>
                <div class="form-group" >
                    <label  class="col-sm-3 control-label">客户QQ：</label>
                    <div class="col-sm-6">
                        <input type="text" class="form-control" name="qq"
                               placeholder="请输入客户QQ"/>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 control-label">客户工作：</label>
                    <div class="col-sm-6">
                        <select class="form-control" name="job.id">
                                <#list jobs! as j>
                                    <option value="${(j.id)!}">${(j.title)!}</option>
                                </#list>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 control-label">客户来源：</label>
                    <div class="col-sm-6">
                        <select class="form-control" name="source.id">
                                <#list sources! as s>
                                    <option value="${(s.id)!}">${(s.title)!}</option>
                                </#list>
                        </select>
                    </div>
                </div>
            </form>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary btn-add-edit">提交</button>
            </div>
        </div>
    </div>
</div>
<#-- 修改状态模态框 -->
<div class="modal fade" id="statusModal" tabindex="-1" role="dialog" aria-labelledby="statusModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="statusModalLabel">修改客户状态</h4>
            </div>
            <form class="form-horizontal" action="/customer/changeStatus.do" method="post" id="statusForm">
                <input type="hidden" name="id" id="statusId">
                <div class="form-group" style="margin-top: 10px;">
                    <label for="parentId" class="col-sm-3 control-label">客户名称：</label>
                    <div class="col-sm-7">
                        <!-- 显示客户的名字 -->
                        <input type="text" class="form-control" id="statusName" name="statusName" readonly >
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-3 control-label">客户状态：</label>
                    <div class="col-sm-7">
                        <select class="form-control" name="status">
                            <option value="0">潜在客户</option>
                            <option value="2">开发失败</option>
                            <option value="4">移入客户池</option>
                        </select>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-statusForm">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>
<#-- 引入跟进模态框 -->
<#include "modal/traceModal.ftl">
<#-- 引入移交模态框 -->
<#include "modal/transferModal.ftl">
</body>
</html>
